#include <head.h>
void wait_test()
{
	pid_t wpid;
	pid_t tmp;
	int i=0;
	for(;i<5;i++){
		tmp= fork();
		if(0== tmp){
			DEBUG_MSG("i=%d,child:%d\n",i,getpid());
			break;
		}
		else if(tmp>0){
			if(i==2){
				wpid=tmp;
			}
		}
	}
	if(tmp==0){
		sleep(i);
	}
	if(i==5){
		/*
		DEBUG_MSG("parent process,wait %d\n",wpid);
		wpid = waitpid(wpid ,NULL,0);
		if(-1==wpid){
			perror("wait error");
			exit(1);
		}
		else {
			DEBUG_MSG("waitpid ok ,%d",wpid);
		}
		*/




		while((wpid = waitpid(-1 ,NULL,WNOHANG))!=-1){
			if(wpid>0){
				DEBUG_MSG("parent process,wait %d\n",wpid);
			}
			else if(wpid == 0){
				sleep(1);
				continue;

			}
		}
	}




	return ;
}
